home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-08-18 | 2.2 KB | 100 lines | [TEXT/R*ch] |
- local
- open Obj Fnlib Config Mixture
- in
-
- (* Qualified identifiers *)
-
- type QualifiedIdent =
- {
- id: string,
- qual: string
- };
-
- (* Constants *)
-
- datatype SCon =
- INTscon of int
- | WORDscon of word
- | CHARscon of char
- | REALscon of real
- | STRINGscon of string
- ;
-
- datatype BlockTag =
- CONtag of int * int (* tag number & span *)
- | EXNtag of QualifiedIdent * int (* constructor name & stamp *)
- ;
-
- datatype StructConstant =
- ATOMsc of SCon
- | BLOCKsc of BlockTag * StructConstant list
- | QUOTEsc of obj ref
- ;
-
- val constUnit =
- BLOCKsc(CONtag(0,1), [])
- ;
-
- fun intOfAtom (INTscon i) = i
- | intOfAtom (WORDscon w) = (magic w) : int
- | intOfAtom (CHARscon c) = Char.ord c
- | intOfAtom _ = fatalError "intOfAtom"
- ;
-
- fun intOfAbsoluteTag (CONtag(i,_)) = i
- | intOfAbsoluteTag (EXNtag _) = fatalError "intOfAbsoluteTag"
- ;
-
- (* Printing structured constants for debugging purposes *)
-
- fun printSeq printEl sep =
- let fun loop [] = ()
- | loop [x] = printEl x
- | loop (x :: xs) = (printEl x; msgString sep; loop xs)
- in loop end
- ;
-
- fun showQualId {qual="", id=id} = id
- | showQualId {qual=u, id=id} = u ^ "." ^ id
- ;
-
- fun printQualId {qual="", id=name} =
- msgString name
- | printQualId {qual=u, id=name} =
- (msgString u; msgString "."; msgString name)
- ;
-
- prim_val sml_makestring_of_char : char -> string
- = 1 "sml_makestring_of_char";
- prim_val sml_makestring_of_string : string -> string
- = 1 "sml_makestring_of_string";
-
- fun printSCon (INTscon i) =
- msgInt i
- | printSCon (WORDscon w) =
- msgWord w
- | printSCon (CHARscon c) =
- msgString (sml_makestring_of_char c)
- | printSCon (REALscon r) =
- msgReal r
- | printSCon (STRINGscon s) =
- msgString (sml_makestring_of_string s)
- ;
-
- fun printCTag (CONtag(tag, span)) =
- (msgInt tag; msgString ":"; msgInt span)
- | printCTag (EXNtag(q, stamp)) =
- (printQualId q; msgString "/"; msgInt stamp)
- ;
-
- fun printStrConst (ATOMsc scon) =
- printSCon scon
- | printStrConst (BLOCKsc(ct, consts)) =
- (msgString "(BLOCK "; printCTag ct; msgString " ";
- printSeq printStrConst " " consts; msgString ")")
- | printStrConst (QUOTEsc rv) =
- msgString "<const>"
- ;
-
- end;
-